package com.umakr.ax.wechat.util;

import net.sf.json.JSONObject;
import org.jeewx.api.core.common.WxstoreUtils;
import org.jeewx.api.core.exception.WexinReqException;
import org.jeewx.api.third.model.ApiAuthorizerToken;
import org.jeewx.api.third.model.ApiAuthorizerTokenRet;
/**
 * @author wangmingdong
 */
public class JwThirdApix {

    private static final String API_AUTHORIZER_TOKEN_URL = "https://api.weixin.qq.com/cgi-bin/component/api_authorizer_token?component_access_token=COMPONENT_ACCESS_TOKEN";

    public static ApiAuthorizerTokenRet apiAuthorizerToken(ApiAuthorizerToken apiAuthorizerToken, String componentAccessToken) throws WexinReqException {
        String requestUrl = API_AUTHORIZER_TOKEN_URL.replace("COMPONENT_ACCESS_TOKEN", componentAccessToken);
        JSONObject param = JSONObject.fromObject(apiAuthorizerToken);
        JSONObject result = WxstoreUtils.httpRequest(requestUrl, "POST", param.toString());
        ApiAuthorizerTokenRet apiAuthorizerTokenRet = (ApiAuthorizerTokenRet)JSONObject.toBean(result, ApiAuthorizerTokenRet.class);
        return apiAuthorizerTokenRet;
    }
}
